/* ***
  **********************************************
  Algoritmo de Monte Carlo - Sequencial  
  **********************************************
*** */ 

/***************
BIBLIOTECAS
***************/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

/***************
FUNCOES
***************/

/*
   RANDOMIZE
   DESCRICAO: Função que ira calcular um numero Randomico
   ENTRADA:   --
   SAIDA:     FLOAT - Numero aleatorio
*/

float randomize(){
	float r1;
	r1 = rand()/(float)RAND_MAX;
	return r1;
}


/***************
PRINCIPAL
***************/

int main(void){
	int i;
	int N_iteracoes = 1000000000 ;
	int dentro_circulo = 0;
	float val1,val2;
	float result;
		
	srand(time(NULL));
	
	i = 0;
	while( i < N_iteracoes){
		val1 = randomize();              
        val2 = randomize();
		//printf("%f\n", val1);
        if(sqrt(val1*val1+val2*val2) <= 1)
			dentro_circulo++;
			
		i++;
	}
                              
    result = (((float)dentro_circulo) / (float)N_iteracoes *(float)4);
    printf("%.6f", result);
	
	
	return 0;
}
